package com.zhang.zhangapp.view.shop;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zhang.zhangapp.R;
import com.zhang.zhangapp.bean.shop.Shop;
import com.zhang.zhangapp.bean.shop.ShopType;
import com.zhang.zhangapp.view.BaseAppCompatActivityActivity;
import com.zhang.zhangapp.view.custom.ShopTypeParentLayout;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2018/4/15.
 */

@ContentView(R.layout.activity_all_type)
public class AllShopTypeActivity extends BaseAppCompatActivityActivity{

    @ViewInject(R.id.shop_type_container)
    LinearLayout containerLayout;
    @ViewInject(R.id.action_bar_title)
    TextView titleText;
    private List<ShopType> shopTypeList;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        shopTypeList = getIntent().getParcelableArrayListExtra("shopTypes");
        x.view().inject(this);
        initView();
    }

    private void initView(){
        for(ShopType shopType : shopTypeList){
            ShopTypeParentLayout layout = new ShopTypeParentLayout(this,shopType);
            layout.setOnClickListener(onItemClickListener);
            containerLayout.addView(layout);
        }
        titleText.setText("全部类别");
    }

    @Event(type = View.OnClickListener.class,value = R.id.action_bar_left_image)
    private void back(View view){
        this.finish();
    }

    AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            openShopList(shopTypeList.get(i).getCode(),shopTypeList.get(i).getName());
        }
    };


    private void openShopList(String type,String name){
        Intent intent = new Intent(this, ShopListActivity.class);
        intent.putExtra("typeCode",type);
        intent.putExtra("title",name);
        startActivity(intent);
    }
}
